from django.db import models
from django.db.models import PROTECT

from apps.users.models import User


class Company(models.Model):
    """公司基本信息表"""

    full_name = models.CharField(max_length=30, null=False, verbose_name='公司全称')
    short_name = models.CharField(max_length=16, null=False, verbose_name='公司简称')
    log_url = models.CharField(max_length=200, verbose_name='公司log')
    web_url = models.CharField(max_length=200, verbose_name='公司网址')
    city = models.CharField(max_length=16, verbose_name='所在城市')
    scale = models.CharField(max_length=30, verbose_name='公司规模')
    dev_stage = models.CharField(max_length=30, verbose_name='发展阶段')
    sketch = models.CharField(max_length=50, verbose_name='公司简述')
    content = models.CharField(max_length=500, null=True, verbose_name='公司详述')
    user = models.ForeignKey(User, on_delete=PROTECT, verbose_name='当前用户')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_company'
        verbose_name = '公司基本信息表'
        verbose_name_plural = verbose_name

    def __str__(self):
        """打印对象时直接打印用户名"""
        return self.short_name


class LabelCompany(models.Model):
    """公司标签表"""

    name = models.CharField(max_length=6, verbose_name='标签名称')
    company = models.ForeignKey(Company, verbose_name='所属公司')

    class Meta:
        db_table = 'tb_company_label'
        verbose_name = '公司标签表'
        verbose_name_plural = verbose_name

    def __str__(self):
        """打印对象时直接打印用户名"""
        return self.name


class FoundTeam(models.Model):
    """创始团队表"""
    person_name = models.CharField(max_length=10, verbose_name='创始人')
    cur_job = models.CharField(max_length=16, verbose_name='当前职位')
    sina_url = models.CharField(max_length=200, verbose_name='微博地址')
    intro = models.CharField(max_length=500, verbose_name='创始人简介')
    header_image = models.CharField(max_length=200, verbose_name='创始人图片')
    company = models.ForeignKey(Company, verbose_name='所属公司')

    class Meta:
        db_table = 'tb_found_team'
        verbose_name = '创始团队表'
        verbose_name_plural = verbose_name

    def __str__(self):
        """打印对象时直接打印用户名"""
        return self.person_name


class CompanyProduct(models.Model):
    """公司产品"""
    poster_url = models.CharField(max_length=200, verbose_name='产品海报')
    name = models.CharField(max_length=30, verbose_name='产品名称')
    url = models.CharField(max_length=200, verbose_name='产品地址')
    intro = models.CharField(max_length=500, verbose_name='产品简述')
    company = models.ForeignKey(Company, verbose_name='所属公司')

    class Meta:
        db_table = 'tb_com_product'
        verbose_name = '公司产品表'
        verbose_name_plural = verbose_name

    def __str__(self):
        """打印对象时直接打印用户名"""
        return self.name


class CompanyDomain(models.Model):
    """公司涉及领域"""
    name = models.CharField(max_length=30, verbose_name='领域名称')
    company = models.ForeignKey(Company, verbose_name='所属公司')

    class Meta:
        db_table = 'tb_com_domain'
        verbose_name = '公司领域表'
        verbose_name_plural = verbose_name

    def __str__(self):
        """打印对象时直接打印用户名"""
        return self.name


class InvestCompany(models.Model):
    """投资公司表"""

    # 可以做成公司的自关联
    name = models.CharField(max_length=30, verbose_name='公司名称')
    dev_stage = models.CharField(max_length=30, verbose_name='发展阶段')
    company = models.ForeignKey(Company, verbose_name='所属公司')

    class Meta:
        db_table = 'tb_invest_company'
        verbose_name = '投资公司表'
        verbose_name_plural = verbose_name

    def __str__(self):
        """打印对象时直接打印用户名"""
        return self.name


class Territory(models.Model):
    """领域"""

    name = models.CharField(max_length=30, verbose_name='领域名称')

    class Meta:
        db_table = 'tb_territory'
        verbose_name = '涉及领域表'
        verbose_name_plural = verbose_name

    def __str__(self):
        """打印对象时直接打印用户名"""
        return self.name
